﻿/// <reference path="../Ref/jquery-1.7.2-vsdoc.js" />
/// <reference path="wme.core.js" />

/* WME Main workspace
/---------------------------------------*/
var wmeWorkspace = function () {
    var rightPaneShow = false;
    var easeSpeed = wmeCore.animationSpeed;

    init = function () {
        //Main windows
        $('.wme-layout-main-left').droppable({
            drop: function (event, ui) {
                var moduleId = $(ui.draggable).attr('wme-data-moduleid');
                var header = $(ui.draggable).attr('wme-data-fullheader');
                loadPane(moduleId, header, 'left');
            }
        });
        $('.wme-layout-main-right').droppable({
            drop: function (event, ui) {
                var moduleId = $(ui.draggable).attr('wme-data-moduleid');
                var header = $(ui.draggable).attr('wme-data-fullheader');
                loadPane(moduleId, header, 'right');
            }
        });

        //Button bindings
        $('#btnToggleRight').click(function () {
            toggleRightPane();
        });
    };

    //Load content to a pane for a specific module
    loadPane = function (moduleId, header, pane) {
        var _pane = $('.wme-layout-main-' + pane);
        _pane.fadeTo(0, 0.1);
        $.getJSON(
            '../Home/GetModuleFullView',
            { moduleId: moduleId },
            function (data) {
                //Load content
                _pane.find('.wme-layout-main-content').html(data);
                //Change header
                _pane.find('label[id=header]').html(header);
                _pane.fadeTo(200, 1);
            }
        );
    };

    //Toggle the right panel
    toggleRightPane = function () {
        if (rightPaneShow) {
            //Collapse right pane
            $('.wme-layout-main-right').removeAttr('style').removeClass('wme-panel-normal').addClass('wme-panel-contract');

            //Full left pane
            $('.wme-layout-main-left').animate({
                width: '100%'
            }, easeSpeed, 'easeInExpo', function () {
                $(this).removeAttr('style').removeClass('wme-panel-normal').addClass('wme-panel-full');
            });

            $('#btnToggleRight').rotate({
                angle: 180,
                animateTo: 0
            });
        }
        else {
            //Expand right pane
            $('.wme-layout-main-right').animate({
                width: '49%'
            }, easeSpeed, 'easeInExpo', function () {
                $(this).removeAttr('style').removeClass('wme-panel-contract').addClass('wme-panel-normal');
            });

            //Half left pane
            $('.wme-layout-main-left').animate({
                width: '49%'
            }, easeSpeed, 'easeInExpo', function () {
                $(this).removeAttr('style').removeClass('wme-panel-full').addClass('wme-panel-normal');
            });

            $('#btnToggleRight').rotate({
                angle: 0,
                animateTo: 180
            });
        }
        rightPaneShow = !rightPaneShow;
    };

    return {
        init: init,
        loadPane: loadPane
    }
} ();